﻿using System.Collections.Generic;
using System.Linq;
using Complaint.Models.Dtos;
using Complaint.Repositories;

namespace Complaint.Models
{
    public class CategoryModel : BaseModel<CategoryRepository>, IModel<Category>
    {
        #region IModel<Category> Members

        public IList<Category> Retrieve()
        {
            return Repository.FindAll().ToList();
        }

        public void Create(Category dto)
        {
            if (dto != null) Repository.Create(dto);
        }

        public void Update(Category dto)
        {
            if (dto != null) Repository.Update(dto);
        }

        public void Delete(Category dto)
        {
            if (dto != null) Repository.Delete(dto);
        }

        public IList<Category> FindByName(string name)
        {
            return Repository.FindByName(name).ToList();
        }

        public Category FindById(int id)
        {
            return Repository.FindById(id);
        }

        #endregion

        public IList<Category> FindByCategory(int id)
        {
            return Repository.FindByCategory(id).ToList();
        }

        public IList<Category> GetCategoryHierarchy(int? id)
        {
            return Repository.GetCategoryHierarchy(id).ToList();
        }

        public IList<Category> GetPopularRoots(int count)
        {
            return Repository.GetPopularRoots(count).ToList();
        }
    }
}